<!DOCTYPE html>
<html>
<head>
    <title>维护规程管理</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <div v-show="showList">
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
<!--            <div class="search-group">-->
<!--                <i-col span="4">-->
<!--                    <i-input v-model="q.name" @on-enter="query" placeholder="名称"></i-input>-->
<!--                </i-col>-->
<!--                <i-button @click="query">查询</i-button>-->
<!--                <i-button @click="reloadSearch">重置</i-button>-->
<!--            </div>-->

        </Row>
        <Row :gutter="16" style="margin: 3px 0px 0px 0px;">
            <div class="buttons-group">
                #if($shiro.hasPermission("devmaintenplan:judgeAndLower"))
                <i-button type="primary" @click="judgeAndLower"><i class="fa fa-level-down"></i>&nbsp;创建维护计划</i-button>
                #end
                <!--                #if($shiro.hasPermission("devmaintenplan:check"))-->
                <!--                <i-button type="primary" @click="check"><i class="fa fa-gavel"></i>&nbsp;审核</i-button>-->
                <!--                #end-->
                <!--                #if($shiro.hasPermission("devmaintenplan:okCheck"))-->
                <!--                <i-button type="primary" @click="okCheck"><i class="fa fa-gavel"></i>&nbsp;审核</i-button>-->
                <!--                #end-->
                <!--                <i-button type="success" @click="addMainBase"><i class="fa fa-bars"></i>&nbsp;维护库</i-button>-->
                <!--                #if($shiro.hasPermission("devmaintenplan:save"))-->
                <!--                <i-button type="info" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</i-button>-->
                <!--                #end-->
                <!--                #if($shiro.hasPermission("devmaintenplan:update"))-->
                <!--                <i-button type="warning" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</i-button>-->
                <!--                #end-->
                <!--                #if($shiro.hasPermission("devmaintenplan:delete"))-->
                <!--                <i-button type="error" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</i-button>-->
                <!--                #end-->
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>

    <div id="reviewLayer" style="display: none;">
        <form class="form-horizontal" style="width: 350px;">
            <div class="form-group">
                <div class="form-group">
                    <div class="col-sm-3 control-label" style="width: 28%;">审核状态</div>
                    <div class="col-sm-8" style="margin-top: 6px">
                        <Radio-group v-model="devMaintenPlan.checkResult">
                            <Radio :label="1" ><span>通过</span></Radio>
                            <Radio :label="2" ><span>不通过</span></Radio>
                        </Radio-group>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <div id="planData" style="display: none">
        <!--<p slot="title">{{title_plan}}</p>-->
        <i-form ref="formValidateResource" :model="maintain_plan" :rules="ValidateResource" :label-width="100">
            <Form-item label="计划名称" prop="planName">
                <i-input v-model="maintain_plan.planName" placeholder="计划名称" class="from_tab_wide"></i-input>
            </Form-item>
            <!--<Form-item label="所属车间" prop="dept">-->
            <!--<i-select v-model="maintain_plan.dept" class="from_tab_wide" @on-change="deptListData">-->
            <!--<i-option v-for="item in deptList" :value="item.DEPT_ID" :key="item.DEPT_ID">{{ item.NAME }}</i-option>-->
            <!--</i-select>-->
            <!--</Form-item>-->
            <Form-item label="生产线" prop="beltline">
                <!--<i-select v-model="maintain_plan.beltline" class="from_tab_wide">-->
                <!--<i-option v-for="item in beltlineList" :value="item.value" :key="item.value">{{ item.label }}</i-option>-->
                <!--</i-select>-->
                <i-input v-model="maintain_plan.beltlineName" disabled @on-click="deptTreeShow" class="from_tab_wide" icon="fa fa-deafness"></i-input>
            </Form-item>
            <Form-item label="执行时间" prop="carryDate">
                <Date-picker v-model="maintain_plan.carryDate" type="datetime" format="yyyy-MM-dd HH:mm"
                             placeholder="选择日期和时间（不含秒）"
                             class="from_tab_wide"></Date-picker>
            </Form-item>
            <Form-item label="完成时间" prop="completeDate">
                <Date-picker v-model="maintain_plan.completeDate" type="datetime" format="yyyy-MM-dd HH:mm"
                             placeholder="选择日期和时间（不含秒）"
                             class="from_tab_wide"></Date-picker>
            </Form-item>
            <Form-item label="备注">
                <i-input v-model="maintain_plan.remark" type="textarea" :autosize="{minRows: 8,maxRows: 5}"
                         placeholder="请输入..."
                         class="from_tab_wide"></i-input>
            </Form-item>
        </i-form>
    </div>
</div>
<div id="categoryLayer" style="display: none;padding:10px;">
    <ul id="categoryTree" class="ztree"></ul>
</div>
<script >
    var code = getQueryString("code");
    $(function () {
        $("#jqGrid").Grid({
            url: '../devmaintenplan/list?devCode=' + code,
            colModel: [

                {label: '设备编码', name: 'devCode', index: 'DEV_CODE', width: 80},
                {label: '版本', name: 'planVersion', index: 'PLAN_VERSION', width: 80},
                {
                    label: '实施频率', name: 'freRate', index: 'FRE_RATE', width: 80,
                    formatter: function (value) {
                        return sysEnums.FRERATE[value];
                    }
                }, // 0每天 1每周 2每个月 3每个季度 4每半年 5一年
                {label: '检查时间非生产', name: 'checkDateUprud', index: 'CHECK_DATE_UPRUD', width: 80},
                {label: '检查时间生产', name: 'checkDatePrud', index: 'CHECK_DATE_PRUD', width: 80},
                {label: '人次', name: 'perEv', index: 'PER_EV', width: 80},
                {label: '内容', name: 'planCon', index: 'PLAN_CON', width: 80},
                {label: '编制人', name: 'orgUserName', index: 'ORG_USER_NAME', width: 80},
                {label: '车间审核人', name: 'checkUserName', index: 'CHECK_USER_NAME', width: 80},
                {
                    label: '审核状态', name: 'checkStatus', index: 'CHECK_STATUS', width: 80,
                    formatter: function (value) {
                        return sysEnums.CHECK_FLAG[value];
                    }
                },
                {
                    label: '审核时间', name: 'checkDate', index: 'CHECK_DATE', width: 80,
                    formatter: function (value) {
                        return transDate(value, "yyyy-MM-dd");
                    }
                },
                {label: 'PE授权人', name: 'okUserName', index: 'OK_USER_NAME', width: 80},
                {
                    label: '批准状态', name: 'okStatus', index: 'OK_STATUS', width: 80,
                    formatter: function (value) {
                        return sysEnums.CHECK_FLAG[value];
                    }
                },
                {
                    label: '批准时间', name: 'okDate', index: 'OK_DATE', width: 80,
                    formatter: function (value) {
                        return transDate(value, "yyyy-MM-dd");
                    }
                },
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            ]
        });
    });


    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "deptId",
                pIdKey: "parentId",
                rootPId: -1
            },
            key: {
                url: "nourl"
            },
        },
        callback: {
            beforeCheck: true,
        }

    };
    var vm = new Vue({
        el: '#rrapp',
        data: {
            showList: true,
            title: null,
            title_plan: '',
            devMaintenPlan: {},
            maintain_plan: {
                devId: '',
                dept: '',
                beltline: '',
                beltlineName: '',
            },
            v_showList: true,
            ruleValidate: {
                name: [
                    {required: true, message: '名称不能为空', trigger: 'blur'}
                ]
            },
            ValidateResource: {
                planName: [
                    {required: true, message: '计划名称不能为空', trigger: 'blur'}
                ],
                carryDate: [
                    {required: true, message: '执行时间不能为空', trigger: 'blur'}
                ],
                dept: [
                    {required: true, message: '所属机构不能为空', trigger: 'blur'}
                ],
                beltline: [
                    {required: true, message: '生产线不能为空', trigger: 'blur'}
                ],
                completeDate: [
                    {required: true, message: '完成时间不能为空', trigger: 'blur'}
                ],
            },
            q: {
                name: ''
            },
            freRateArray: enumsToList("FRERATE"),
            deptList: [],
            beltlineList: [],
        },
        methods: {
            getTreeShow: function () {
                //加载分类树
                Ajax.request({
                    url: '../sys/user/treeDeptByType/DT_CJKSCX',
                    async: true,
                    successCallback: function (r) {
                        ztree = $.fn.zTree.init($("#categoryTree"), setting, r.list);
                        ztree.expandAll(true);
                    }
                });
            },
            judgeAndLower: function () {
                var id = getSelectedRow("#jqGrid");
                if (!id) {
                    return;
                }
                vm.getTreeShow();
                vm.deptList = [];
                $.ajax({
                    url: '../sysMsg/queryDept',
                    type: 'GET',
                    success(value) {
                        if (value.deptList.length > 0) {
                            for (var list in value.deptList) {
                                if (value.deptList.hasOwnProperty(list)) {
                                    vm.deptList.push(value.deptList[list]);
                                }
                            }
                        }
                    }
                })
                vm.maintain_plan.devId = id;
                $.ajax({
                    url: '../maintainplan/queryModulMaintianId',
                    type: 'GET',
                    data: {"id": id},
                    success(res) {
                        if (res.msg) {
                            alert(res.msg, "function");
                        } else {
                            vm.title_plan = '评判并下发';
                            openWindow({
                                title: '创建维护计划',
                                area: ['40%', '90%'],
                                content: jQuery("#planData"),
                                btn: ['确定', '取消'],
                                btn1: function (index) {
                                    Ajax.request({
                                        url: '../maintainplan/inMaintain',
                                        type: 'POST',
                                        params: vm.maintain_plan,
                                        successCallback: function (allData) {
                                            layer.close(index)
                                            vm.maintain_plan = {}
                                        }
                                    })
                                },
                                btn2: function (index) {
                                    vm.maintain_plan = {}
                                }
                            })
                        }
                    }
                });
            },
            deptTreeShow: function () {
                openWindow({
                    title: "选择生产线",
                    area: ['300px', '450px'],
                    content: jQuery("#categoryLayer"),
                    btn: ['确定', '取消'],
                    btn1: function (index) {
                        var node = ztree.getSelectedNodes();
                        vm.maintain_plan.dept = node[0].parentId;
                        if (node[0].deptType == 'DT_CJKSCX') {
                            // //选择上级菜单
                            vm.maintain_plan.beltline = node[0].deptId;
                            vm.maintain_plan.beltlineName = node[0].name;
                            layer.close(index);
                        }
                    }
                });
            },
        }
    })
</script>
</body>
</html>
<style>
    .from_tab_wide {
        width: 90% !important;
        padding-top: 1% !important;
    }
</style>
